package algorithm.leetcode;

/**
 * @author bingo
 * @Description    采用递归的方式实现
 * @Date 2018/6/6
 */
public class Solution2 {
    public ListNode removeElements(ListNode head, int val,int deep){
        System.out.print(generate(deep));
        System.out.println("               ["+head+"]");
        if(head==null) {
            System.out.print(generate(deep));
            System.out.print(" head==null;return");
            return null;
        }
        ListNode listNode = removeElements(head.next,val,deep=deep+1);
        if(head.val == val){
            System.out.print(generate(deep));
            System.out.println("               ["+head+"]");
            return  listNode;
        }
        else{
            System.out.print(generate(deep));
            System.out.println("               ["+head+"]");
             head.next=listNode;
             return  head;
        }

    }

    private String generate(int deep) {
        StringBuilder res = new StringBuilder();
        for(int i=0;i<deep;i++){
            res.append("->");
        }
        return  res.toString();
    }

    public static void main(String[] args) {
        int[] arr = {1,2,3};
        ListNode listNode = new ListNode(arr);
        Solution2 solution = new Solution2();
        solution.removeElements(listNode,3,0);

    }

}
